package cn.b.sky.mes.qm.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import cn.b.sky.mes.qm.dao.QualityReportDao;
import cn.b.sky.mes.qm.model.QualityReport;
import cn.b.sky.mes.qm.model.StatisticData;
import cn.b.sky.mes.qm.model.condition.QualityReportCondition;
import cn.b.sky.mes.qm.service.QualityReportService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service("qualityReportService")
public class QualityReportServiceImpl implements QualityReportService {

  private static final String DEFECTLEVEL = "defectLevel";

  private static final String DEFECTTYPE = "defectType";

  private static final String RESPONSIBILITYTYPE = "responsibilityType";

  @Resource
  QualityReportDao qualityReportDao;

  @Override
  public List<QualityReport> selectAllQualityReportList(QualityReportCondition condition) {
    return qualityReportDao.selectAllQualityReportList(condition);
  }

  @Override
  public int selectQualityReportCount(QualityReportCondition condition) {
    //  Auto-generated method stub
    return 0;
  }

  @Override
  public List<StatisticData> selectListGroupByType(QualityReportCondition condition, String groupType) {

    if (StringUtils.isBlank(groupType)) {
      return null;
    }
    List<StatisticData> list = null;

    if (DEFECTLEVEL.equals(groupType)) {
      list = qualityReportDao.selectListGroupByDefectLevel(condition);
    } else if (DEFECTTYPE.equals(groupType)) {
      list = qualityReportDao.selectListGroupByDefectType(condition);
    } else if (RESPONSIBILITYTYPE.equals(groupType)) {
      list = qualityReportDao.selectListGroupByResponsibilityType(condition);
    }
    return list;
  }

  @Override
  public List<Map<String, Object>> selectAllQualityReportMapList(QualityReportCondition condition) {
    return qualityReportDao.selectAllQualityReportMapList(condition);
  }

}
